package com.example.yiwei.crm.view.activity.healthActivity;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.dao.dockDao;
import com.example.yiwei.crm.dao_impl.dockDaoImpl;
import com.example.yiwei.crm.data.GetDock;
import com.example.yiwei.crm.data.GetDockData;
import com.example.yiwei.crm.entity.dockingEntity;
import com.example.yiwei.crm.view.Class.listviewClass.ListAdapter;
import com.example.yiwei.crm.view.Class.listviewClass.departmentListAdapter;
import com.example.yiwei.crm.view.Class.listviewClass.managerSelectListAdapter;

import java.util.List;
import java.util.Map;

import static com.example.yiwei.crm.data.GetDockData.dockingEntityList;

public class departmentSelectActivity extends AppCompatActivity {
private ImageView img_back,img_commit;
    private ListView lstv;
    private departmentListAdapter ladapter;
    List<dockingEntity> dockingEntityList;
    private String department_id="";
    private String department_name="";
    dockingEntity dockingEntity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_department_select);
        lstv= (ListView) findViewById(R.id.department_select_listview);
        img_back= (ImageView) findViewById(R.id.department_select_img_back);
        img_commit= (ImageView) findViewById(R.id.department_select_img_commit);
        lstv.setDivider(new ColorDrawable(Color.rgb(216, 216, 216)));
        lstv.setDividerHeight(1);
        lstv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        new Thread(new Runnable() {
            @Override
            public void run() {
                dockDao dockDao=new dockDaoImpl();
                dockingEntityList=dockDao.queryDepartmentMessage(baseClass.find_department_message_url,null);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ladapter = new departmentListAdapter(departmentSelectActivity.this,dockingEntityList);
                        lstv.setAdapter(ladapter);
                        ladapter.notifyDataSetChanged();

                    }
                });
            }
        }).start();
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        img_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final List<String> list3 = departmentListAdapter.getNames();
                for (int i=0;i<list3.size();i++){
                   department_name=list3.get(i)+","+department_name;
                }
                final List<String> list4 = departmentListAdapter.getIDs();
                for (int i=0;i<list4.size();i++){
                    department_id=list4.get(i)+","+department_id;
                }
                GetDock.dockingEntity1.setManager_department(department_name);
                GetDock.dockingEntity1.setManager_department_id(department_id);
                Log.d("op", GetDock.dockingEntity1.getManager_department_id()+"");
                if (GetDock.dockingEntity1!=null){
                    finish();
                }
            }
        });

    }
}
